<?php

namespace app\controller\main;

use linkphp\jwt\Jwt;

class Auth
{

    public function isLogin()
    {
        if(isset($_SERVER['HTTP_AUTHORIZATION'])
            && $_SERVER['HTTP_AUTHORIZATION'] != null
            && $_SERVER['HTTP_AUTHORIZATION'] != ''
            && $_SERVER['HTTP_AUTHORIZATION'] != 'null'){
            $data = Jwt::parse($_SERVER['HTTP_AUTHORIZATION']);
            if(Jwt::verify($data,'123')){
                return ['code' => 1, 'data' => Jwt::arrays($data['payload'])];
            } else {
                return ['code' => 304, 'msg' => '非法请求!'];
            }
        } else {
            return ['code' => 2, 'msg' => '还未登入!'];
        }
    }

    public function logout(){}

    public function getUserInfo()
    {
        if(isset($_SERVER['HTTP_AUTHORIZATION'])
            && $_SERVER['HTTP_AUTHORIZATION'] != null
            && $_SERVER['HTTP_AUTHORIZATION'] != ''
            && $_SERVER['HTTP_AUTHORIZATION'] != 'null'){
            $data = Jwt::parse($_SERVER['HTTP_AUTHORIZATION']);
            if(Jwt::verify($data,'123')){
                return Jwt::arrays($data['payload']);
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

}